<div class="layuimini-main">
	<div class="layui-form layuimini-form" lay-filter="form-data">
		<div class="layui-form-item">
			<label class="layui-form-label required">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="userName" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">角色类型</label>
			<div class="layui-input-block">
				<input type="radio" name="roleType" value="0" title="普通用户">
				<input type="radio" name="roleType" value="1" title="管理员">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">邮箱</label>
			<div class="layui-input-block">
				<input type="email" name="email" placeholder="请输入邮箱" class="layui-input" autocomplete="off">
			</div>
		</div>
		<input type="hidden" name="loginName">
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
			</div>
		</div>
	</div>
</div>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
			parentIndex = layer.index,
			parentData = JSON.parse(parent.data);
		
		//给表单赋值
		form.val("form-data", {
		  "loginName": parentData.loginName
		  ,"userName": parentData.userName
		  ,"roleType": parentData.roleType
		  ,"email": parentData.email
		});
		
        //监听提交
        form.on('submit(saveBtn)', function (data) {
			$.ajax({
				url: '/sysUser/updateUser',
				type: 'POST',
				dataType: "json",
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(data.field),
				success: function(data){
					if(data.code != "000000"){
						layer.msg(data.message, {icon: 5, shift: 6});
						return false;
					}
					layer.close(parentIndex);
					layer.msg("保存成功", {
						icon: 1,
						time: 500,
						shade: 0.01,
						shadeClose: false}, function(){
						parent.layui.table.reload('currentTableId');
					});
				},
				error: function(data){
					layer.msg(data.message, {icon: 5, shift: 6});
				}
			});

            return false;
        });

    });
</script>